package com.iqiao.common.base.db;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.support.DaoSupport;
import org.springframework.util.Assert;

/**
 * Created by flt on 2017/11/10.
 */
public class BaseMyBatisDao extends DaoSupport {


    /**
     *  注入sqlSessionFactory。
     */
    @Autowired
    private SqlSessionFactory sqlSessionFactory;
    /**
     * 注入sqlSessionTemplate。
     */
    @Autowired
    private SqlSessionTemplate sqlSessionTemplate;

    @Override
    protected void checkDaoConfig() throws IllegalArgumentException {
        Assert.notNull(sqlSessionFactory, "sqlSessionFactory must be not null");
    }

    /**
     * 返回SqlSessionFactory
     * @return
     */
    public SqlSessionFactory getSqlSessionFactory()
    {
        return sqlSessionFactory;
    }

    /**
     * 注入sqlSessionFactory
     * @param sqlSessionFactory
     */
    public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    /**
     * 返回sqlSessionTemplate
     * @return
     */
    public SqlSessionTemplate getSqlSessionTemplate()
    {
        return sqlSessionTemplate;
    }
}
